#include <stdio.h>
#include <string.h>

#include "common.h"

#include "conn_mgr.h"

#include "http.h"

#include "esp_log.h"
#include "driver/gpio.h"

#include "esp_intr_alloc.h"

#include "sdkconfig.h"
#include "esp_task_wdt.h"

char *TAG = "common";

int request(char *url, char *method, char *data, char *response, int response_size)
{
    // strcpy(response, url);
    int ret = http_process(url, method, data, response, response_size);
    if (ret != ESP_OK)
    {
        ESP_LOGE(TAG, "http_get_task error");
        return ESP_FAIL;
    }
    return ESP_OK;
}

// 函数定义  
int isElementInArray(int arr[], int size, int element) {  
    for (int i = 0; i < size; i++) {  
        if (arr[i] == element) {  
            return 1;  
        }  
    }  
    return 0;  
}

void turn_led(int stat)
{
    // ESP_LOGI(TAG, "Example configured to blink GPIO LED!");
    gpio_set_level(LED_GPIO, stat);
    ESP_LOGI("LED", "%s灯状态已设置\n", stat == LED_ON ? "开" : "关");
}


void configure_led(void)
{
    ESP_LOGI("LED", "Configured to blink GPIO LED!");
    gpio_set_level(LED_GPIO, LED_OFF);
    gpio_set_level(22, 1);
    gpio_set_direction(22, GPIO_MODE_OUTPUT);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(LED_GPIO, GPIO_MODE_OUTPUT);
}
